package com.zixue.springcloud.controller;

import com.zixue.springcloud.entities.CommonResult;
import com.zixue.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class OrderController {

    @Value("${PROVIDER_PATH}")
    private  String restPath;

    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/order/create")
    public CommonResult create(@RequestBody Payment payment){
        ResponseEntity<CommonResult> commonResultResponseEntity = restTemplate.postForEntity(restPath + "/Payment/create", payment, CommonResult.class);
        CommonResult body = commonResultResponseEntity.getBody();
        return body;
    }
    @GetMapping("/order/payment/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){
        CommonResult forObject = restTemplate.getForObject(restPath + "/Payment/getPaymentById/" + id, CommonResult.class);
        return forObject;
    }

}
